<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        div {
            width: 800px;
            height: 500px;
            border: 1px solid black;
            margin: auto;
        }
    </style>
    <script src="./node_modules/jquery/dist/jquery.min.js"></script>
</head>

<body>
    <div>
        <form action="">
            <label> id: <input type="text" name="id" /> </label>
            <label>名字<input type="text" name="name" value="123" /></label>
            <label>价格：<input type="text" name="price" value="13" /> </label>
            <label>颜色: <input type="text" name="color" value="123" /></label>
        </form>
        <button id="Add to">添加</button>
        <button id="delete">删除</button>
        <button id="revise">修改</button>
        <button id="search">搜索id</button>
        <button id="fetch">获取amme</button>
    </div>
    <script>
        $(function() {
            $("#Add to").on("click", function() {
                var data = $("form").serialize();
                $.ajax({
                    url: "http://localhost:3000/api/Create",
                    type: "post",
                    data: data,
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                    },
                });
            });
            //删除
            $("#delete").click(function() {
                var data = $("form").serialize();
                $.ajax({
                    url: "http://localhost:3000/api/Delete",
                    type: "DELETE",
                    data: data,
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                    },
                });
            });
            //修改
            $("#revise").on("click", function() {
                console.log(1111);
                var data = $("form").serialize();
                $.ajax({
                    url: "http://localhost:3000/api/Update",
                    type: "PUT",
                    data: data,
                    success: function(res) {
                        console.log(res);
                    },
                });
            });
        });
    </script>
</body>

</html>